//
//  TZLivenessDetector.h
//  mtcnn_test
//
//  Created by panda on 07/03/2018.
//  Copyright © 2018 panda. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "TZ_LivenessMacro.h"

#define NWD_LANDMARK_POINTS_NUM 5
#define NWD_FACE_RECT_NUM 4
#define NWD_MAX_COUNT 10
#define NWD_FACE_ARRAY_COUNT 5
#define NWD_FRAMES 5
#define NWD_BOXES_COUNT 4
#define NWD_LANDMARK_COUNT 14

typedef NS_ENUM(NSInteger, GestureType) {
    GestureType_Blink = 1,
    GestureType_Mouth,
    GestureType_Shake,
    GestureType_Nod
};

typedef struct _return_face_rect{
    NSInteger face_count;
    
    //张嘴闭嘴  close:0,open:1
    NSInteger mouth_flag;
    
    //close:0,open:1
    NSInteger eye_flag;
    
    //左眼睁闭情况 close:0,open:1
    NSInteger left_eye_flag;
    
    //右眼睁闭情况 close:0,open:1
    NSInteger right_eye_flag;
    
    //摇头 middle:0, left：1，right：2
    NSInteger head_shake_flag;
    
    //点头 middle:0, up：2，down：1
    NSInteger head_nod_flag;
    
    //0(legal face)/-1(no face)
    NSInteger state;
    
    //1(near)/0(middle)/2(far)
    NSInteger face_pos_state;

    BOOL isXAxisMoveSlow;
    BOOL isXAxisMoveFast;
    BOOL isYAxisMoveSlow;
    BOOL isYAxisMoveFast;
    
    float score;
    //0 正常, 1 退出
    NSInteger  exit_state;

    BOOL isMaskContainsFace;

    float centerX;
    float centerY;
    float width;
    float height;
    float area_ratio;
    float NWDLandmarks[NWD_LANDMARK_COUNT];
    float NWDBboxes[NWD_BOXES_COUNT];
    
}return_face_rect;

@protocol LivenessDectionProtocol <NSObject>

/**
 动作识别阶段检测过程，调用此方法。
 
 @param info 人脸的相关信息。
 */
- (void)onFrameDetectedWithinfo:(struct _return_face_rect *)info;

/**
 照镜子阶段检测过程，调用此方法。

 @param info 人脸的相关信息。
 */
- (void)onQualityDetection:(struct _return_face_rect *)info;

@end

@interface TZLivenessDetector : NSObject

+ (instancetype)share;

- (void)setDelegate:(id<LivenessDectionProtocol>)delegate;

- (void)livenessDetectWithOriginalImage:(UIImage*)image trimmedImage:(UIImage *)trimmedImage action:(enum MGLivenessDetectionType)action;

- (void)closeSeccion;

- (UIImage *)bestImage;

@end
